﻿Imports Negocio
Public Class frmImpresionProgramacion

    Dim servicio1 As New ProgramacionNegocio
    Dim servicio2 As New TurnoNegocio

    Dim empezar As Boolean = False

    Dim formu As New rptProgramacion_V2

    Sub listarTurnos()
        Dim ds As DataSet = servicio2.listarTurnos()

        With cboTurno
            .DataSource = ds.Tables(0)
            .ValueMember = "TUR_Codigo"
            .DisplayMember = "TUR_Descripcion"
        End With
    End Sub

    Sub listarProgramacion()
        Dim ds As DataSet = servicio1.obtenerProgramacion(dtpFecha.Text, cboTurno.SelectedValue.ToString)

        dgvProgramación.DataSource = ds.Tables(0)

        If ds.Tables(0).Rows.Count <> 0 Then
            dgvProgramación.Rows(0).Selected = False
        Else
            formu.SetParameterValue("@VEH", "")
            formu.SetParameterValue("@TUR", "")
            formu.SetParameterValue("@FEC", "")
            formu.SetParameterValue("@Fecha", "")
            Me.crvContenedor.ReportSource = formu
        End If
    End Sub

    Private Sub dtpFecha_TextChanged(sender As Object, e As System.EventArgs) Handles dtpFecha.TextChanged
        listarProgramacion()
    End Sub

    Private Sub dgvProgramación_CellClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvProgramación.CellClick
        Dim f As Integer = e.RowIndex

        If f > -1 Then
            formu.SetParameterValue("@Fecha", dtpFecha.Text)
            formu.SetParameterValue("@VEH", dgvProgramación.Item("Column2", f).Value)
            formu.SetParameterValue("@FEC", dtpFecha.Text)
            formu.SetParameterValue("@TUR", cboTurno.SelectedValue.ToString)
            Me.crvContenedor.ReportSource = formu
        End If
    End Sub

    Private Sub frmImpresionProgramacion_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        listarTurnos()
        formu.SetParameterValue("@VEH", "")
        formu.SetParameterValue("@TUR", "")
        formu.SetParameterValue("@FEC", "")
        formu.SetParameterValue("@Fecha", "")
        Me.crvContenedor.ReportSource = formu
        empezar = True
    End Sub

    Private Sub btnImprimir_Click(sender As System.Object, e As System.EventArgs) Handles btnImprimir.Click
        formu.PrintToPrinter(1, False, 0, 0)
    End Sub

    Private Sub btnSalir_Click(sender As System.Object, e As System.EventArgs) Handles btnSalir.Click
        frmMenu.vezImprePro = 0
        Me.Close()
    End Sub

    Private Sub frmImpresionProgramacion_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        frmMenu.vezImprePro = 0
    End Sub

    Private Sub cboTurno_SelectedValueChanged(sender As Object, e As System.EventArgs) Handles cboTurno.SelectedValueChanged
        If empezar = True Then
            listarProgramacion()
        End If
    End Sub

    Private Sub btnExportar_Click(sender As System.Object, e As System.EventArgs) Handles btnExportar.Click
        Me.crvContenedor.ExportReport()
    End Sub
End Class